import UniShare from '@/uni_modules/uni-share/js_sdk/uni-share.js';
const uniShare = new UniShare();
module.exports = {
	// #ifndef APP-PLUS
	onBackPress({
		from
	}) {
		console.log(from);
		if (from == 'backbutton') {
			this.$nextTick(function() {
				uniShare.hide()
			})
			return uniShare.isShow;
		}
	},
	// #endif
	onLoad() {
		// 设置默认的转发参数
		const userinfo = this.$store.state.vuex_userInfo
		const title = userinfo && userinfo.is_power ? `把关师${userinfo.name}向您推荐` : userinfo.is_gen ?
			`${userinfo.nickname}向您推荐` : '决策变简单 就找帮把关'
		this.$u.mpShare = {
			title: title, // 默认为小程序名称
			path: 'pages/index/index?spid=' + userinfo.uid || '',
			imageUrl: this.$u.api.getAppImage('mp-share-cover.png'),
		}
		this.updateConfig()
	},
	mounted() {

	},
	data() {
		return {
			appThemeColor: ``
		}
	},
	// #ifdef MP
	onShareAppMessage() {
		return this.$u.mpShare
	},
	// #endif
	// #ifndef MP
	onShareTimeline() {
		return this.$u.mpShare
	},
	// #endif
	methods: {
		async updateConfig() {
			const res = await this.$u.api.public.appconfig()
			this.$appConfig.MIN_PRICE = res.demand_min_price
			this.$appConfig.MAX_PRICE = res.demand_max_price
			this.$appConfig.S_MIN_PRICE = res.serve_min_price
			this.$appConfig.S_MAX_PRICE = res.serve_max_price
			this.$appConfig.mainColor = res.main_color
			this.$appConfig.mainColorLight = res.fuse_color
			// this.setConfig()
		},
		setConfig() {
			this.appThemeColor =
				`--main-color: ${this.$appConfig.mainColor};--main-color-light: ${this.$appConfig.mainColorLight}`;
		},
		uniShare(params) {
			uniShare.show({
				content: { //公共的分享参数配置  类型（type）、链接（herf）、标题（title）、summary（描述）、imageUrl（缩略图）
					type: 0,
					href: 'https://app.bangbaguan.com/' + params.path,
					title: params.title || '帮把关',
					summary: params.desc || '决策变简单 就找帮把关',
					imageUrl: params.imageUrl || this.$u.api.getAppImage('mp-share-cover.png'),
				},
				menus: [{
						"img": this.$u.api.getAppImage('icon_weixin.png'),
						"text": "微信好友",
						"share": { //当前项的分享参数配置。可覆盖公共的配置如下：分享到微信小程序，配置了type=5
							"provider": "weixin",
							"scene": "WXSceneSession"
						}
					},
					{
						"img": this.$u.api.getAppImage('icon_pengyouquan.png'),
						"text": "微信朋友圈",
						"share": {
							"provider": "weixin",
							"scene": "WXSceneTimeline"
						}
					},
					{
						"img": this.$u.api.getAppImage('ic_xiaochengxu.png'),
						"text": "微信小程序",
						"share": {
							provider: "weixin",
							scene: "WXSceneSession",
							type: 5,
							miniProgram: {
								id: 'gh_d277302b54d3',
								path: params.path,
								webUrl: 'params.path',
								type: 0
							},
						}
					},
				],
				cancelText: "取消分享",
			}, e => { //callback
				console.log(uniShare.isShow);
				console.log(e);
			})
		}
	}
}